package com.sunda.spmsweb.overseacontroller;

import com.sunda.spmscommon.ResponseResult;
import com.sunda.spmsoversea.dto.WerksAllStorageInvSearchDTO;
import com.sunda.spmsoversea.dto.WerksStorageInvSearchDTO;
import com.sunda.spmsoversea.dto.WhsOperateLogSearchDTO;
import com.sunda.spmsoversea.dto.WhsStorageInvSearchDTO;
import com.sunda.spmsoversea.service.IWhsOperateLogService;
import com.sunda.spmsoversea.service.IWhsStorageInventoryService;
import com.sunda.spmsweb.util.JWTUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @program: spms
 * @description:
 * @author: Wayne Wu
 * @create: 2022-01-06 10:49
 **/
@RestController
@RequestMapping("/overseaWhsStorageInv")
@Api(tags = "海外仓仓库库存信息查询", description = "海外仓仓库库存信息查询接口")
public class OverseaWhsStorageInventoryController {

    @Autowired
    IWhsStorageInventoryService iWhsStorageInventoryService;

    @Autowired
    IWhsOperateLogService iWhsOperateLogService;

    @RequestMapping("/getWerksStorageInvList")
    @ApiOperation(value = "获取工厂内库存明细分页", notes = "获取工厂内库存明细分页\n" +
            "工厂代码必输，其余字段可选输入，搜索结果范围不包括 CN01；\n" +
            "示例参数：\n" +
            "{\n" +
            "\t\"werks\": \"GF02\",\n" +
            "\t\"searchInfo\": \"210008389\",\n" +
            "\t\"storageArea\": \"A\",\n" +
            "\t\"storageNo\": \"\",\n" +
            "\t\"current\": 1,\n" +
            "\t\"size\": 20\n" +
            "}", httpMethod = "POST")
    public ResponseResult getWerksStorageInvList(@RequestBody WerksStorageInvSearchDTO werksStorageInvSearchDTO){
        try {
            String userId = JWTUtil.getUserId(SecurityUtils.getSubject().getPrincipal().toString());
            return iWhsStorageInventoryService.getWerksStorageInvList(werksStorageInvSearchDTO);
        }catch (Exception e){
            e.printStackTrace();
            return ResponseResult.error("请求数据失败").add("error", e.getMessage());
        }
    }

    @RequestMapping("/getWerksAllStorageInv")
    @ApiOperation(value = "获取工厂内库存全部明细", notes = "获取工厂内库存全部明细\n" +
            "工厂代码必输，其余字段可选输入，搜索结果范围不包括 CN01；\n" +
            "示例参数：\n" +
            "{\n" +
            "\t\"werks\": \"TF02\",\n" +
            "\t\"searchInfo\": \"\",\n" +
            "\t\"storageArea\": \"EQ\",\n" +
            "\t\"storageNo\": \"\"\n" +
            "}", httpMethod = "POST")
    public ResponseResult getWerksAllStorageInv(@RequestBody WerksAllStorageInvSearchDTO werksAllStorageInvSearchDTO){
        try {
            String userId = JWTUtil.getUserId(SecurityUtils.getSubject().getPrincipal().toString());
            return iWhsStorageInventoryService.getWerksAllStorageInv(werksAllStorageInvSearchDTO);
        }catch (Exception e){
            e.printStackTrace();
            return ResponseResult.error("请求数据失败").add("error", e.getMessage());
        }
    }

    @RequestMapping("/getStorageInvList")
    @ApiOperation(value = "获取跨工厂库存信息分页", notes = "获取跨工厂库存信息分页\n" +
            "所有字段可选输入，搜索结果范围不包括 CN01，工厂字段忽略 CN01；\n" +
            "示例参数：\n" +
            "{\n" +
            "\t\"werks\": \"\",\n" +
            "\t\"searchInfo\": \"螺丝\",\n" +
            "\t\"current\": 1,\n" +
            "\t\"size\": 20\n" +
            "}", httpMethod = "POST")
    public ResponseResult getStorageInvList(@RequestBody WhsStorageInvSearchDTO whsStorageInvSearchDTO){
        try {
            String userId = JWTUtil.getUserId(SecurityUtils.getSubject().getPrincipal().toString());
            return iWhsStorageInventoryService.getStorageInvList(whsStorageInvSearchDTO);
        }catch (Exception e){
            e.printStackTrace();
            return ResponseResult.error("请求数据失败").add("error", e.getMessage());
        }
    }

    @RequestMapping("/getStorageInvByMaterialNo")
    @ApiOperation(value = "按工厂代码料号查询所有储位分布", notes = "按工厂代码料号查询所有储位分布\n" +
            "所有字段都必输，搜索结果范围不包括 CN01；\n" +
            "示例参数：\n" +
            "werks = GF02， materialNo = 210053126", httpMethod = "POST")
    public ResponseResult getWerksStorageByMaterialNo(@RequestParam String werks, @RequestParam String materialNo){
        try {
            String userId = JWTUtil.getUserId(SecurityUtils.getSubject().getPrincipal().toString());
            return iWhsStorageInventoryService.getWerksStorageByMaterialNo(werks, materialNo);
        }catch (Exception e){
            e.printStackTrace();
            return ResponseResult.error("请求数据失败").add("error", e.getMessage());
        }
    }

    @RequestMapping("/getWhsOperateLog")
    @ApiOperation(value = "带关联单据号日志查询分页", notes = "带关联单据号日志查询分页\n" +
            "海外仓日志查询，查询条件固定后端控制 documentType = 4，返回结构带关联单据号；\n" +
            "返回参数说明：relateDocumentNumber 日志记录关联单据号主键(uuid或DN)；\n" +
            "            overseaWhsInNo 入库任务单号；\n" +
            "            sapDeliveryNote 其他收货交货单号；\n" +
            "            overseaWhsOutNo 出库任务单号；\n" +
            "            overseaOtherTaskNo 其他出入库任务单号；\n" +
            "            overseaWhsMoveNo 调拨任务单号；\n" +
            "示例参数说明：createUser 创建人工号/创建人姓名；\n" +
            "            searchInfo 物料编号/物料英文描述/物料中文描述；\n" +
            "            movementType 移动类型；\n" +
            "示例参数：\n" +
            "{\n" +
            "\t\"werks\": \"TF02\",\n" +
            "\t\"whsLocationCode\": \"1006\",\n" +
            "\t\"storageArea\": \"\",\n" +
            "\t\"storageNo\": \"\",\n" +
            "\t\"createUser\": \"\",\n" +
            "\t\"searchInfo\": \"\",\n" +
            "\t\"movementType\": \"\",\n" +
            "\t\"beginDate\": \"2022-01-22 12:00:00\",\n" +
            "\t\"endDate\": \"2022-01-24 10:00:00\",\n" +
            "\t\"current\": 1,\n" +
            "\t\"size\": 20\n" +
            "}", httpMethod = "POST")
    public ResponseResult getWhsOperateLog(@RequestBody WhsOperateLogSearchDTO whsOperateLogSearchDTO){
        try {
            String userId = JWTUtil.getUserId(SecurityUtils.getSubject().getPrincipal().toString());
            return iWhsOperateLogService.getWhsOperateLog(whsOperateLogSearchDTO);
        }catch (Exception e){
            e.printStackTrace();
            return ResponseResult.error("请求数据失败").add("error", e.getMessage());
        }
    }

    @RequestMapping("/getWhsOperateLogList")
    @ApiOperation(value = "带关联单据号日志查询不分页", notes = "带关联单据号日志查询不分页\n" +
            "海外仓日志查询，查询条件固定后端控制 documentType = 4，返回结构带关联单据号；\n" +
            "返回参数说明：relateDocumentNumber 日志记录关联单据号主键(uuid或DN)；\n" +
            "            overseaWhsInNo 入库任务单号；\n" +
            "            sapDeliveryNote 其他收货交货单号；\n" +
            "            overseaWhsOutNo 出库任务单号；\n" +
            "            overseaOtherTaskNo 其他出入库任务单号；\n" +
            "            overseaWhsMoveNo 调拨任务单号；\n" +
            "示例参数说明：createUser 创建人工号/创建人姓名；\n" +
            "            searchInfo 物料编号/物料英文描述/物料中文描述；\n" +
            "            movementType 移动类型；\n" +
            "示例参数：\n" +
            "{\n" +
            "\t\"werks\": \"TF02\",\n" +
            "\t\"whsLocationCode\": \"1006\",\n" +
            "\t\"storageArea\": \"\",\n" +
            "\t\"storageNo\": \"\",\n" +
            "\t\"createUser\": \"\",\n" +
            "\t\"searchInfo\": \"\",\n" +
            "\t\"movementType\": \"\",\n" +
            "\t\"beginDate\": \"2022-01-22 12:00:00\",\n" +
            "\t\"endDate\": \"2022-01-24 12:00:00\"\n" +
            "}", httpMethod = "POST")
    public ResponseResult getWhsOperateLogList(@RequestBody WhsOperateLogSearchDTO whsOperateLogSearchDTO){
        try {
            String userId = JWTUtil.getUserId(SecurityUtils.getSubject().getPrincipal().toString());
            return iWhsOperateLogService.getWhsOperateLogList(whsOperateLogSearchDTO);
        }catch (Exception e){
            e.printStackTrace();
            return ResponseResult.error("请求数据失败").add("error", e.getMessage());
        }
    }

    //@RequestMapping("/checkErrorDate")
    //@ApiOperation(value = "checkErrorDate", notes = "checkErrorDate\n" +
    //        "", httpMethod = "GET")
    //public ResponseResult checkErrorDate(){
    //    try {
    //        String userId = JWTUtil.getUserId(SecurityUtils.getSubject().getPrincipal().toString());
    //        return iWhsOperateLogService.checkErrorDate();
    //    }catch (Exception e){
    //        e.printStackTrace();
    //        return ResponseResult.error("请求数据失败").add("error", e.getMessage());
    //    }
    //}

}
